COVID-19 statistics and trend

In [1]:
import pandas as pd
import os
import plotly.graph_objects as go
import plotly.io as pio
import plotly.offline as py
from scipy.optimize import curve_fit
from datetime import datetime
import re
In [2]:
pd.set_option("display.max_rows", 250)
In [3]:
pio.renderers.default = 'notebook'
In [4]:
from datetime import datetime

now = datetime.now()

current_time = now.strftime("%d-%m-%Y %H:%M")
print("Updated on", current_time, "h")
Updated on 02-07-2020 12:00 h
In [5]:
################################ Loading xls
In [6]:
url = "https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide.xlsx"
In [7]:
cases = pd.read_excel(url)
In [8]:
#filepath = "C:\\Users\\edidd\\Documents\\Ubiqum\\Data Analytics Course\\covid19\\data\\"
In [9]:
#cases = pd.read_excel(os.path.join(filepath, "COVID-19-geographic-disbtribution-worldwide-2020-04-23.xlsx"))
In [10]:
# filepath2 = "C:\\Users\\edidd\\Documents\\covid19_JHU_CSSE\\COVID-19\\"
In [11]:
# data_jhu= pd.read_csv(os.path.join(filepath2, "who_covid_19_situation_reports\\who_covid_19_sit_rep_time_series\\who_covid_19_sit_rep_time_series.csv"))
In [12]:
############################# Data wrangling
In [13]:
cases.dateRep = pd.to_datetime(cases.dateRep, format="%Y-%m-%d")
In [14]:
cases = cases.rename(columns= {
    "dateRep": "date", 
    "countriesAndTerritories": "country", 
    "cases": "newcases", 
    "deaths": "newdeaths"})
In [15]:
cases = cases.sort_values(by=["country", "date"])
In [16]:
cases["cumcases"]= cases.groupby("country")["newcases"].cumsum()
In [17]:
######################### Deleting rows with 0 cumulative cases
In [18]:
cases= cases.loc[cases.cumcases != 0,:]
In [19]:
cases= cases.set_index("country")

Summary

In [20]:
# Grouping by country
In [21]:
cases_total= cases.groupby(["country"]).sum().sort_values(by= ["newcases"], ascending= False)
In [22]:
cases_total= cases_total.rename(columns= {"newcases": "total_cases", "newdeaths": "total_deaths"})
In [23]:
cases_total= cases_total.drop(["day", "month", "year", "popData2019", "cumcases"], axis= "columns")
In [24]:
cases_total["death_ratio"]= cases_total.total_deaths / cases_total.total_cases * 100
In [25]:
cases_total["population_2019"]= cases.groupby("country").max().popData2019
In [26]:
cases_total["cases_to_population"]= cases_total.total_cases / cases_total.population_2019 * 100
In [27]:
cases_total["cases_to_population"]= cases_total["cases_to_population"].map('{:,.2f}%'.format)
In [28]:
cases_total["death_ratio"]= cases_total["death_ratio"].map('{:,.2f}%'.format)

Global total of confirmed cases

10446353

Totals per country

In [30]:
fig = go.Figure(data= [go.Bar(x= cases_total.index, 
                              y= cases_total.total_cases.head(10), 
                              text= "*" + cases_total.cases_to_population, 
                              textposition='auto')
                      ]
               )
fig.update_layout(title= "Total confirmed cases per country - top 10", 
                  xaxis_title= "* Showing percentage of country's population")
fig.show()
In [31]:
morethan1000 = cases_total.loc[cases_total.total_cases >= 1000, :].copy()
In [32]:
morethan1000["death_ratio"] = morethan1000.total_deaths / morethan1000.total_cases
In [33]:
fig= go.Figure()

fig.add_trace(go.Histogram(x= morethan1000.death_ratio, 
                           histnorm= "probability",
                           xbins=dict(
                               start=0,
                               end=morethan1000.death_ratio.max(),
                               size=.01
                           )
                          )
             )

fig.update_layout(title= "Global distribution of death ratio", 
                 xaxis=dict(tickformat= "%", tickangle=0, 
                            title='* Only countries with more than 999 reported cases are considered'))

pio.show(fig)

Complete list

total_cases total_deaths death_ratio population_2019 cases_to_population
country
United_States_of_America 2634432 127410 4.84% 3.290649e+08 0.80%
Brazil 1402041 59594 4.25% 2.110495e+08 0.66%
Russia 647849 9320 1.44% 1.458723e+08 0.44%
India 585493 17400 2.97% 1.366418e+09 0.04%
United_Kingdom 312654 43730 13.99% 6.664711e+07 0.47%
Peru 285213 9677 3.39% 3.251046e+07 0.88%
Chile 279393 5688 2.04% 1.895204e+07 1.47%
Spain 249271 28355 11.38% 4.693706e+07 0.53%
Italy 240578 34767 14.45% 6.035955e+07 0.40%
Iran 227662 10817 4.75% 8.291389e+07 0.27%
Mexico 226089 27769 12.28% 1.275755e+08 0.18%
Pakistan 213470 4395 2.06% 2.165653e+08 0.10%
Turkey 199906 5131 2.57% 8.200388e+07 0.24%
Germany 194725 8985 4.61% 8.301921e+07 0.23%
Saudi_Arabia 190823 1649 0.86% 3.426853e+07 0.56%
France 164801 29843 18.11% 6.701288e+07 0.25%
South_Africa 151209 2657 1.76% 5.855827e+07 0.26%
Bangladesh 145483 1847 1.27% 1.630462e+08 0.09%
Canada 104193 8591 8.25% 3.741104e+07 0.28%
Colombia 97846 3334 3.41% 5.033944e+07 0.19%
Qatar 96088 113 0.12% 2.832071e+06 3.39%
China 84785 4641 5.47% 1.433784e+09 0.01%
Sweden 68451 5333 7.79% 1.023018e+07 0.67%
Egypt 68311 2953 4.32% 1.003881e+08 0.07%
Argentina 64517 1307 2.03% 4.478068e+07 0.14%
Belarus 62118 392 0.63% 9.452409e+06 0.66%
Belgium 61509 9754 15.86% 1.145552e+07 0.54%
Ecuador 56432 4527 8.02% 1.737366e+07 0.32%
Indonesia 56385 2876 5.10% 2.706256e+08 0.02%
Netherlands 50273 6113 12.16% 1.728216e+07 0.29%
Iraq 49109 1943 3.96% 3.930979e+07 0.12%
United_Arab_Emirates 48667 315 0.65% 9.770526e+06 0.50%
Kuwait 46195 354 0.77% 4.207077e+06 1.10%
Ukraine 44998 1173 2.61% 4.399364e+07 0.10%
Singapore 43907 26 0.06% 5.804343e+06 0.76%
Portugal 42141 1576 3.74% 1.027662e+07 0.41%
Oman 40070 176 0.44% 4.974992e+06 0.81%
Philippines 37514 1266 3.37% 1.081166e+08 0.03%
Poland 34393 1463 4.25% 3.797281e+07 0.09%
Panama 33550 631 1.88% 4.246440e+06 0.79%
Bolivia 33219 1123 3.38% 1.151310e+07 0.29%
Dominican_Republic 32568 747 2.29% 1.073896e+07 0.30%
Switzerland 31631 1683 5.32% 8.544527e+06 0.37%
Afghanistan 31517 746 2.37% 3.804176e+07 0.08%
Romania 26970 1651 6.12% 1.941446e+07 0.14%
Bahrain 26758 87 0.33% 1.641164e+06 1.63%
Nigeria 25694 590 2.30% 2.009636e+08 0.01%
Armenia 25542 443 1.73% 2.957728e+06 0.86%
Ireland 25473 1736 6.82% 4.904240e+06 0.52%
Israel 25244 320 1.27% 8.519373e+06 0.30%
Kazakhstan 21819 188 0.86% 1.855143e+07 0.12%
Honduras 19558 497 2.54% 9.746115e+06 0.20%
Japan 18723 974 5.20% 1.268603e+08 0.01%
Guatemala 18096 773 4.27% 1.758148e+07 0.10%
Austria 17777 705 3.97% 8.858775e+06 0.20%
Ghana 17741 112 0.63% 3.041786e+07 0.06%
Azerbaijan 17524 213 1.22% 1.004772e+07 0.17%
Moldova 16613 545 3.28% 4.043258e+06 0.41%
Serbia 14564 277 1.90% 6.963764e+06 0.21%
Algeria 13907 912 6.56% 4.305305e+07 0.03%
Nepal 13564 29 0.21% 2.860872e+07 0.05%
South_Korea 12850 282 2.19% 5.122532e+07 0.03%
Denmark 12768 605 4.74% 5.806081e+06 0.22%
Cameroon 12592 313 2.49% 2.587639e+07 0.05%
Morocco 12533 228 1.82% 3.647177e+07 0.03%
Czechia 11954 349 2.92% 1.064980e+07 0.11%
Cote_dIvoire 9499 68 0.72% 2.571655e+07 0.04%
Sudan 9258 572 6.18% 4.281324e+07 0.02%
Norway 8865 250 2.82% 5.328212e+06 0.17%
Malaysia 8639 121 1.40% 3.194979e+07 0.03%
Uzbekistan 8627 26 0.30% 3.298172e+07 0.03%
Australia 7834 104 1.33% 2.520320e+07 0.03%
Puerto_Rico 7465 153 2.05% 2.933404e+06 0.25%
Finland 7214 328 4.55% 5.517919e+06 0.13%
Democratic_Republic_of_the_Congo 7038 169 2.40% 8.679057e+07 0.01%
Senegal 6793 112 1.65% 1.629636e+07 0.04%
El_Salvador 6438 174 2.70% 6.453550e+06 0.10%
Kenya 6366 148 2.32% 5.257397e+07 0.01%
North_Macedonia 6350 302 4.76% 2.077132e+06 0.31%
Haiti 5975 105 1.76% 1.126308e+07 0.05%
Tajikistan 5954 52 0.87% 9.321023e+06 0.06%
Ethiopia 5846 103 1.76% 1.120787e+08 0.01%
Venezuela 5832 51 0.87% 2.851583e+07 0.02%
Kyrgyzstan 5735 62 1.08% 6.415851e+06 0.09%
Gabon 5394 42 0.78% 2.172578e+06 0.25%
Guinea 5391 33 0.61% 1.277125e+07 0.04%
Bulgaria 4989 230 4.61% 7.000039e+06 0.07%
Djibouti 4682 54 1.15% 9.735570e+05 0.48%
Bosnia_and_Herzegovina 4453 185 4.15% 3.300998e+06 0.13%
Luxembourg 4299 110 2.56% 6.138940e+05 0.70%
Hungary 4155 585 14.08% 9.772756e+06 0.04%
Mauritania 4149 126 3.04% 4.525698e+06 0.09%
Central_African_Republic 3745 47 1.26% 4.745179e+06 0.08%
Costa_Rica 3459 16 0.46% 5.047561e+06 0.07%
Greece 3409 192 5.63% 1.072460e+07 0.03%
Thailand 3173 58 1.83% 6.962558e+07 0.00%
Somalia 2924 90 3.08% 1.544291e+07 0.02%
Kosovo 2878 51 1.77% 1.798506e+06 0.16%
Croatia 2777 107 3.85% 4.076246e+06 0.07%
Palestine 2765 9 0.33% 4.981422e+06 0.06%
Albania 2535 62 2.45% 2.862427e+06 0.09%
Nicaragua 2519 83 3.29% 6.545503e+06 0.04%
Maldives 2361 9 0.38% 5.309570e+05 0.44%
Cuba 2341 86 3.67% 1.133348e+07 0.02%
Paraguay 2221 17 0.77% 7.044639e+06 0.03%
Madagascar 2214 20 0.90% 2.696931e+07 0.01%
Mali 2181 116 5.32% 1.965802e+07 0.01%
Sri_Lanka 2047 11 0.54% 2.132373e+07 0.01%
South_Sudan 2006 37 1.84% 1.106211e+07 0.02%
Equatorial_Guinea 2001 32 1.60% 1.355982e+06 0.15%
Estonia 1989 69 3.47% 1.324820e+06 0.15%
Iceland 1842 10 0.54% 3.569910e+05 0.52%
Lithuania 1817 78 4.29% 2.794184e+06 0.07%
Lebanon 1778 34 1.91% 6.855709e+06 0.03%
Slovakia 1667 28 1.68% 5.450421e+06 0.03%
Guinea_Bissau 1654 24 1.45% 1.920917e+06 0.09%
Slovenia 1600 111 6.94% 2.080908e+06 0.08%
Zambia 1594 24 1.51% 1.786103e+07 0.01%
Sierra_Leone 1462 60 4.10% 7.813207e+06 0.02%
Malawi 1265 16 1.26% 1.862875e+07 0.01%
Congo 1245 40 3.21% 5.380504e+06 0.02%
Cape_Verde 1227 15 1.22% 5.499360e+05 0.22%
Benin 1199 21 1.75% 1.180115e+07 0.01%
New_Zealand 1178 22 1.87% 4.783062e+06 0.02%
Tunisia 1174 50 4.26% 1.169472e+07 0.01%
Yemen 1158 312 26.94% 2.916192e+07 0.00%
Jordan 1132 9 0.80% 1.010170e+07 0.01%
Latvia 1118 30 2.68% 1.919968e+06 0.06%
Niger 1075 67 6.23% 2.331072e+07 0.00%
Rwanda 1025 2 0.20% 1.262694e+07 0.01%
Cyprus 998 19 1.90% 8.758990e+05 0.11%
Burkina_Faso 962 53 5.51% 2.032138e+07 0.00%
Uruguay 936 27 2.88% 3.461731e+06 0.03%
Georgia 928 15 1.62% 3.996762e+06 0.02%
Mozambique 889 6 0.67% 3.036604e+07 0.00%
Uganda 889 0 0.00% 4.426959e+07 0.00%
Chad 866 74 8.55% 1.594688e+07 0.01%
Andorra 855 52 6.08% 7.617700e+04 1.12%
Libya 824 24 2.91% 6.777453e+06 0.01%
Eswatini 812 11 1.35% 1.148133e+06 0.07%
Liberia 780 36 4.62% 4.937374e+06 0.02%
Sao_Tome_and_Principe 714 13 1.82% 2.150480e+05 0.33%
Jamaica 702 10 1.42% 2.948277e+06 0.02%
San_Marino 698 42 6.02% 3.445300e+04 2.03%
Cases_on_an_international_conveyance_Japan 696 7 1.01% NaN nan%
Malta 670 9 1.34% 4.935590e+05 0.14%
Togo 650 14 2.15% 8.082359e+06 0.01%
Zimbabwe 591 7 1.18% 1.464547e+07 0.00%
Montenegro 548 12 2.19% 6.221820e+05 0.09%
Suriname 517 13 2.51% 5.813630e+05 0.09%
United_Republic_of_Tanzania 509 21 4.13% 5.800546e+07 0.00%
Taiwan 447 7 1.57% 2.377388e+07 0.00%
Western_Sahara 380 1 0.26% 5.824580e+05 0.07%
Vietnam 355 0 0.00% 9.646211e+07 0.00%
Mauritius 341 10 2.93% 1.269670e+06 0.03%
Isle_of_Man 336 24 7.14% 8.458900e+04 0.40%
Jersey 319 31 9.72% 1.077960e+05 0.30%
Comoros 303 7 2.31% 8.508910e+05 0.04%
Myanmar 299 6 2.01% 5.404542e+07 0.00%
Angola 284 13 4.58% 3.182530e+07 0.00%
Syria 279 9 3.23% 1.707013e+07 0.00%
Guam 267 5 1.87% 1.672950e+05 0.16%
Guernsey 252 13 5.16% 6.446800e+04 0.39%
Guyana 245 12 4.90% 7.827750e+05 0.03%
Botswana 227 1 0.44% 2.303703e+06 0.01%
Mongolia 220 0 0.00% 3.225166e+06 0.01%
Eritrea 203 0 0.00% 3.497117e+06 0.01%
Namibia 203 0 0.00% 2.494524e+06 0.01%
Cayman_Islands 200 1 0.50% 6.494800e+04 0.31%
Faroe_Islands 187 0 0.00% 4.867700e+04 0.38%
Gibraltar 177 0 0.00% 3.370600e+04 0.53%
Burundi 170 1 0.59% 1.153058e+07 0.00%
Bermuda 146 9 6.16% 6.250800e+04 0.23%
Cambodia 141 0 0.00% 1.648654e+07 0.00%
Brunei_Darussalam 141 3 2.13% 4.332960e+05 0.03%
Trinidad_and_Tobago 130 8 6.15% 1.394969e+06 0.01%
Bahamas 104 11 10.58% 3.894860e+05 0.03%
Aruba 103 3 2.91% 1.063100e+05 0.10%
Monaco 103 5 4.85% 3.308500e+04 0.31%
Barbados 97 7 7.22% 2.870210e+05 0.03%
United_States_Virgin_Islands 84 6 7.14% 1.045790e+05 0.08%
Liechtenstein 83 1 1.20% 3.837800e+04 0.22%
Sint_Maarten 77 15 19.48% 4.238900e+04 0.18%
Bhutan 77 0 0.00% 7.630940e+05 0.01%
Antigua_and_Barbuda 66 3 4.55% 9.711500e+04 0.07%
French_Polynesia 62 0 0.00% 2.792850e+05 0.02%
Gambia 47 2 4.26% 2.347696e+06 0.00%
Turks_and_Caicos_islands 41 2 4.88% 3.819400e+04 0.11%
Northern_Mariana_Islands 30 2 6.67% 5.721300e+04 0.05%
Saint_Vincent_and_the_Grenadines 29 0 0.00% 1.105930e+05 0.03%
Belize 28 2 7.14% 3.903510e+05 0.01%
Lesotho 27 0 0.00% 2.125267e+06 0.00%
Curaçao 25 1 4.00% 1.634230e+05 0.02%
Timor_Leste 24 0 0.00% 1.293120e+06 0.00%
Grenada 23 0 0.00% 1.120020e+05 0.02%
New_Caledonia 21 0 0.00% 2.827570e+05 0.01%
Saint_Lucia 19 0 0.00% 1.827950e+05 0.01%
Laos 19 0 0.00% 7.169456e+06 0.00%
Fiji 18 0 0.00% 8.899550e+05 0.00%
Dominica 18 0 0.00% 7.180800e+04 0.03%
Saint_Kitts_and_Nevis 15 0 0.00% 5.283400e+04 0.03%
Greenland 13 0 0.00% 5.666000e+04 0.02%
Falkland_Islands_(Malvinas) 13 0 0.00% 3.372000e+03 0.39%
Holy_See 12 0 0.00% 8.150000e+02 1.47%
Montserrat 11 1 9.09% 4.991000e+03 0.22%
Seychelles 11 0 0.00% 9.774100e+04 0.01%
Papua_New_Guinea 11 0 0.00% 8.776119e+06 0.00%
British_Virgin_Islands 8 1 12.50% 3.003300e+04 0.03%
Bonaire, Saint Eustatius and Saba 7 0 0.00% 2.598300e+04 0.03%
Anguilla 3 0 0.00% 1.487200e+04 0.02%

Trends shown for countries with more than 999 reported cases. Double-click on a country name in the legend next to each figure, in order to show only the selected country.

In [35]:
cases_total= cases_total.sort_values("country")
In [36]:
country_list= ["Italy", "Germany", "Spain", "South_Korea", "United_States_of_America", "China", "Iran", "France", "United_Kingdom", "Singapore", "Australia", "Ecuador"]
In [37]:
country_list= cases_total.loc[cases_total.total_cases >= 1000, :].index
In [39]:
fig = go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].date, 
                             y= cases.loc[country].cumcases, 
                             mode= "markers",
                             name= country))
fig.update_layout(title="Cummulative cases per country")#, yaxis_type="log")
pio.show(fig)
In [41]:
# cases["growfactor"] = cases.newcases / cases.groupby("country")["newcases"].shift(1).fillna(0)

Exponential fitting

In [44]:
cases= cases.loc[cases.cumcases >= 20,:]
In [45]:
cases["datemin"] = cases.groupby("country")["date"].min()
In [46]:
cases["days"]= cases.date - cases.datemin
In [47]:
cases.days= cases.days.dt.days
In [48]:
def exponential_growth(x, a, c_o):
    return c_o*a**x
In [49]:
def country_fit(df, country):
    x= df.loc[country].days
    y= df.loc[country].cumcases
    popt, pcov= curve_fit(exponential_growth, x, y)
    return popt
In [50]:
# country_list= ["Italy", "Germany", "Spain", "South_Korea", "United_States_of_America", "Singapore"]
In [51]:
popt_list= []
popt_df= pd.DataFrame(columns= ["A"])
In [52]:
for i, country in enumerate(country_list):
    popt_list.append(country_fit(cases, country))
    popt_df.loc[country]= popt_list[i][0]

Factor A of exponential growth (C = Co * A^d)

It can be interpreted as an average daily increase factor of total cases.

In [53]:
popt_df.sort_values("A", ascending= False)
Out[53]:
A
Mauritania 1.069952
Nepal 1.068050
Iraq 1.063288
Malawi 1.056828
Ethiopia 1.055846
South_Africa 1.052848
Benin 1.050789
Guatemala 1.048218
Central_African_Republic 1.047855
Honduras 1.047653
Argentina 1.046524
Bolivia 1.046513
Oman 1.045858
Yemen 1.045786
Haiti 1.045726
Venezuela 1.045634
Kenya 1.043593
Colombia 1.043337
Bangladesh 1.042999
Nicaragua 1.042554
India 1.042030
Chile 1.042011
Madagascar 1.041034
Brazil 1.040498
Pakistan 1.039737
Egypt 1.039342
Armenia 1.039192
Azerbaijan 1.039101
Cote_dIvoire 1.037726
El_Salvador 1.037664
Nigeria 1.037428
Mexico 1.037239
South_Sudan 1.036611
Afghanistan 1.036245
Democratic_Republic_of_the_Congo 1.035838
Gabon 1.035672
Kyrgyzstan 1.034985
Sudan 1.034530
Bahrain 1.034122
Cape_Verde 1.033876
Saudi_Arabia 1.033452
Cameroon 1.032509
Ghana 1.031909
Kuwait 1.031748
Peru 1.031100
Kazakhstan 1.030715
Qatar 1.030401
Palestine 1.030359
Panama 1.030019
Senegal 1.029795
Indonesia 1.029674
Sierra_Leone 1.029528
Congo 1.029277
Tajikistan 1.029058
North_Macedonia 1.028907
Zambia 1.028860
Equatorial_Guinea 1.028483
Russia 1.027833
Paraguay 1.027360
Moldova 1.027335
Costa_Rica 1.027116
Rwanda 1.027077
Philippines 1.026843
Uzbekistan 1.026747
Puerto_Rico 1.026483
Djibouti 1.026420
Dominican_Republic 1.026286
Mali 1.026194
Ukraine 1.026037
Belarus 1.025973
Kosovo 1.025358
Maldives 1.024978
United_Arab_Emirates 1.024705
Somalia 1.024558
Guinea_Bissau 1.023721
Guinea 1.023384
Sweden 1.023306
Sri_Lanka 1.022893
Singapore 1.022679
Albania 1.022525
Bulgaria 1.022397
Algeria 1.022244
Poland 1.020740
Ecuador 1.020442
United_States_of_America 1.020279
Morocco 1.020159
Iran 1.018296
Canada 1.018253
Bosnia_and_Herzegovina 1.018161
Romania 1.018161
United_Kingdom 1.017554
Lebanon 1.016272
Jordan 1.016152
Japan 1.015836
Serbia 1.015622
Turkey 1.015570
Portugal 1.015214
Cuba 1.014715
Hungary 1.014441
Malaysia 1.014261
Finland 1.013784
Ireland 1.013621
Denmark 1.013169
Israel 1.013123
Netherlands 1.013053
France 1.012740
Czechia 1.012672
Belgium 1.012531
Germany 1.012249
Italy 1.011687
Thailand 1.011446
Slovakia 1.011414
Spain 1.011347
Greece 1.011049
Latvia 1.010672
Australia 1.010582
Niger 1.010560
Lithuania 1.010333
Croatia 1.010184
Norway 1.009943
Tunisia 1.009861
Switzerland 1.009842
Estonia 1.009662
Austria 1.009580
Slovenia 1.008061
Iceland 1.008036
Luxembourg 1.008031
South_Korea 1.007907
New_Zealand 1.006408
China 1.005917

Exponential fitting

In [54]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].days, 
                             y= cases.loc[country].cumcases, 
                             mode= "markers",
                             name= country))
    fig.add_trace(go.Scatter(x= cases.loc[country].days,
                             y= exponential_growth(cases.loc[country].days, *popt_list[i]),
                             mode= "lines",
                             name= "exponential fit"))
fig.update_layout(title= "Exponential fit per country")

pio.show(fig)

Change in the number of reported new cases

A positive change means an increase in the number of reported cases. A negative change means a decrease in the number of new cases, that means good news!

In [55]:
country_list= ["Italy", "Germany", "Spain", "South_Korea", "United_States_of_America", "China", "Iran", "France", "United_Kingdom", "Singapore", "Australia", "Ecuador"]
In [56]:
country_list= cases_total.loc[cases_total.total_cases >= 1000, :].index
In [57]:
cases["growspeed"]= cases.newcases - cases.groupby("country").newcases.shift(1).fillna(0)
In [58]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].date, 
                             y= cases.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Daily change in number of new cases")

pio.show(fig)
In [59]:
#### Grow speed with different aggregations
In [60]:
cases= cases.reset_index()
In [61]:
cases= cases.set_index("date")
In [62]:
cases_2d= cases.groupby("country").resample(pd.Timedelta(days= 2)).sum().loc[:,["newcases"]]
In [63]:
cases_3d= cases.groupby("country").resample(pd.Timedelta(days= 3)).sum().loc[:,["newcases"]]
In [64]:
cases_4d= cases.groupby("country").resample(pd.Timedelta(days= 4)).sum().loc[:,["newcases"]]
In [65]:
cases_7d= cases.groupby("country").resample(pd.Timedelta(days= 7)).sum().loc[:,["newcases"]]
In [66]:
# Grow speed
In [67]:
cases_2d["growspeed"]= cases_2d.newcases - cases_2d.groupby("country").newcases.shift(1).fillna(0)
In [68]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_2d.loc[country].index, 
                             y= cases_2d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (2 days period)")
pio.show(fig)
In [69]:
cases_3d["growspeed"]= cases_3d.newcases - cases_3d.groupby("country").newcases.shift(1).fillna(0)
In [70]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_3d.loc[country].index, 
                             y= cases_3d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (3 days period)")

pio.show(fig)
In [71]:
cases_4d["growspeed"]= cases_4d.newcases - cases_4d.groupby("country").newcases.shift(1).fillna(0)
In [72]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_4d.loc[country].index, 
                             y= cases_4d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (4 days period)")
pio.show(fig)
In [73]:
cases_7d["growspeed"]= cases_7d.newcases - cases_7d.groupby("country").newcases.shift(1).fillna(0)
In [74]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_7d.loc[country].index, 
                             y= cases_7d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (1 week period)")
pio.show(fig)
In [75]:
cases= cases.reset_index()
In [76]:
cases= cases.set_index("country")
In [77]:
#!jupyter nbconvert --to html --template toc2 EAP.ipynb